const { Renewal, Counter } = require('../common/mysql.js')
const { Op } = require('sequelize')

module.exports = {
    async insert(renewal) {
        await Renewal.create(renewal)
    },
    async getAllByCounterId(id, store_id) {
        return await Renewal.findAll({
            include: [
                {
                    model: Counter,
                    where: {
                        store_id: {
                            [Op.eq]: store_id
                        }
                    },
                    attributes: []
                }
            ],
            where: {
                counter_id: {
                    [Op.eq]: id
                }
            }
        })
    },
    async update(id, month) {
        await Renewal.update(
            {
                month: month
            },
            {
                fields: ['month'],
                where: {
                    id: {
                        [Op.eq]: id
                    }
                }
            }
        )
    },
    async del(id) {
        await Renewal.destroy({
            where: {
                id: {
                    [Op.eq]: id
                }
            }
        })
    }
}
